$(function() {
	$('#vue_vm_list').hide();
});

var materialApply = {
	materialApplyId: '',
	materialId: '',
	materialName: '',
	applyQuantity: '',
	subjectRoomId: getLoginedUser().subjectRoomId,
	subjectRoomName: getLoginedUser().subjectRoomName,
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	remark: '',
	grantStatus: 0,
};

var mat_operation_vue_vm = {
	data: materialApply
};

if($('#mat_operation_vue_vm').length > 0) {
	var vue_vm = new Vue({
		el: '#mat_operation_vue_vm',
		data: view
	});
}

function materialApply_find() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list').hide();
	
	var subjectRoomId = $('#subjectRoom_select').val();
	
	find_basic_by_json(path+'/materialApply/find', {subjectRoomId: subjectRoomId}, function(response) {	
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		for(var i=0; i<response.data.length; i++) {
			response.data[i].index = i+1;
		}
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				materialApply_grantOne:function(todo) {
					if(confirm('确实要发放材料吗？')) {
						save_basic_by_json(path+'/materialApply/grantOne', {id:todo.materialApplyId}, function() {
							$('#'+todo.materialApplyId+'_button').remove();
							alert('发放成功');
						});
					}
				},
				materialApply_deleteOne:function(todo) {
					if(confirm('确实要删除材料申请吗？')) {
						save_basic_by_json(path+'/materialApply/deleteOne', {id:todo.materialApplyId}, function() {
							$('#'+todo.materialApplyId+'_div').remove();
							alert('删除成功');
						});
					}
				}
			}
		});
		
		$('#vue_vm_list').show();
	});
}

function materialApply_save() {
	mat_operation_vue_vm.data.applyQuantity = parseInt($('#applyQuantity').val());
	if(!mat_operation_vue_vm.data.materialId || mat_operation_vue_vm.data.materialId=='') {
		alert('请选择材料');
		return;
	}
	if(!mat_operation_vue_vm.data.applyQuantity || mat_operation_vue_vm.data.applyQuantity==0) {
		alert('请输入数量');
		return;
	}
	
	save_basic(path+'/materialApply/save', {materialApply:materialApply}, function() {
		alert('申请成功');
	});
}